package cn.jhz.filesharingsystem.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.jhz.filesharingsystem.model.Pager;
import cn.jhz.filesharingsystem.model.User;

/**
 * userDao的实现类
 * @author asus
 */
@Repository("userDao")
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {

	@Override
	public List<User> getAllUsers() {
		String hql = "from User";
		return super.list(hql, null, null);
	}

	@Override
	public Pager<User> getAllPagerUsers(String username, boolean state) {
		String hql = "FROM User u WHERE 1=1";
		if(username != null && !"".equals(username))
				hql += " and u.username like '%"+username+"%'";
		if(state) {
			hql += "and u.role.roleName !='super' AND u.role.roleName !='admin' ";
		}
		return super.find(hql, null, null);
	}
	
	@Override
	public User loadUserByEmail(String email) {
		String hql = "SELECT u FROM User u WHERE u.email=?0";
		return (User) super.queryByHql(hql, new Object[] {email}, null);
	}

	@Override
	public User loadUserByUserName(String username) {
		String hql = "SELECT u FROM User u WHERE u.username=?0";
		return (User) super.queryByHql(hql, new Object[] {username}, null);
	}
	
}
